﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLDC.Common.Estate;
using System.Data;
using System.Text;
namespace ZLDC.Estate.Quantify
{
    public partial class lp_Configuration_below : System.Web.UI.Page
    {
        public string t_id = "";//分配工作人的部门ID
        public string u_id = "";//分配工作人的ID;
        public bool exists = false;
        public string mainId = "0";//任务主表ID  Repeater1请选择 
        public string type = "";//类型 1为今日工作部署 2为预约工作安排
        public string daytime = "";//预约时间
        public string showTime = "";//页面显示时间
        public string endday = "";//预约结束日期
        public string Rrow = "";//父页面的行号
        public string deptlist = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            onload();
        }

        #region
        protected void onload()
        {
            //deptlist = ZLDC.Topo.BLL.Estate.lp_Basis.GetDeptList(_Utility.GetInfoBySession().m_sDeptID);
            deptlist = _Utility.GetInfoBySession().m_sUserID;
            t_id = _Request.GetString("t_id", "0");
            u_id = _Request.GetString("user_id", "0");
            type = _Request.GetString("type", "0");
            daytime = _Request.GetString("daytime", "0");
            endday = _Request.GetString("endday", "0");
            Rrow = _Request.GetString("Rrow", "");
            DataSet ds = new DataSet();
            if (type == "2")
            {
                showTime = "预约工作日期：<a style='color:red'>" + daytime + "" + (endday == "0" ? "" : "~" + endday + "") + "</a>";
                ds = ZLDC.Topo.BLL.Estate.lp_Basis.Getds("select leave,ID,isComplete,choiceType from lp_Configuration_main where userID=" + u_id + " and DATEDIFF(dd, workday, '" + daytime + "') = 0 ");
            }
            if (type == "1")
            {
                ds = ZLDC.Topo.BLL.Estate.lp_Basis.Getds("select leave,ID,isComplete,choiceType from lp_Configuration_main where userID=" + u_id + " and DATEDIFF(dd, workday, '" + DateTime.Now + "') = 0 ");
            }
            if (ZLDC.Topo.BLL.Estate.lp_Basis.rtcount(ds))
            {
                if (ds.Tables[0].Rows.Count > 0)//是否已有数据 修改 或者添加
                {
                    mainId = ds.Tables[0].Rows[0]["ID"].ToString();
                    if (ds.Tables[0].Rows[0]["leave"].ToString() == "1")
                    {
                        btnAdd.Enabled = false;
                    }
                    exists = true;
                 
                }
            }
            if (!IsPostBack)
            {
                txtTotal1.Value = ZLDC.Topo.BLL.Estate.lp_Basis.Exists_Set();//获取最低分数
                txtTotal2.Value = txtTotal1.Value;
                GetDrop(deptlist);
                GetTb(type);
            }
        }
        #endregion

        protected void GetDrop(string deptlist)
        {
            //ZLDC.Topo.BLL.Estate.lp_Basis.droplist(dropPK, "Name", "Name", "select Name from lp_Package  where deptid="+_Utility.GetInfoBySession().m_sDeptID+" Group by Name");
            ZLDC.Topo.BLL.Estate.lp_Basis.droplist(dropPK, "type", "namevalue", "select Other3 as namevalue,Name,(Name+CASE WHEN Other2='' then '' else '('+isnull(Other2,'')+')' end)  type from lp_Package  where CreateUser = (" +deptlist + ") Group by Name,Other2,Other3");

        }
        protected void GetTb(string type)
        {
            
            string name = dropPK.SelectedValue;
            ZLDC.Topo.BLL.Estate.lp_Configuration_below.GetTb(type, name, RpList, u_id, daytime, Panel2, Panel1, txtallnum2, Repeater1, exists, txtallnum1);
           
        }
       
        protected bool Gettr(object obj)
        {

            if (obj.ToString() == "1")
            { return true; }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 下拉列表重新绑定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void dropPK_SelectedIndexChanged(object sender, EventArgs e)
        {
                GetTb(type);
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            ZLDC.Topo.BLL.Estate.lp_Configuration_below.BtnAdd(exists, dropPK, txtallnum2, txtallnum1, mainId, type, txtTotal2, Page, u_id, daytime, RpList, Repeater1,endday,Rrow);
        }

       

    }
}
